﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

public partial class MasterPages_Principal : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Boolean autenticado = false;
        if (!HttpContext.Current.Request.Url.ToString().EndsWith(ConfigurationManager.AppSettings["PaginaDeLoginMobile"]))
        {
            if (Session[ConfigurationManager.AppSettings["autenticado"]] != null)
            {
                autenticado = (Boolean)Session[ConfigurationManager.AppSettings["autenticado"]];
            }

            if (!autenticado)
            {
                salir();
            }
            else
            {
                LinkButtonSalir.Visible = true;
            }
        }
    }

    protected void LinkButtonSalir_Click(object sender, EventArgs e)
    {
        Session[ConfigurationManager.AppSettings["idUsuario"]] = null;
        Session[ConfigurationManager.AppSettings["nombreUsuario"]] = null;
        Session[ConfigurationManager.AppSettings["claveUsuario"]] = null;
        Session[ConfigurationManager.AppSettings["perfilUsuario"]] = null;
        Session[ConfigurationManager.AppSettings["autenticado"]] = null;
        salir();
    }

    private void salir()
    {
        Response.Redirect(@"~\" + ConfigurationManager.AppSettings["PaginaDeLoginMobile"]);
    }
}
